package com.qf.give_a_like.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.give_a_like.domain.Crad;
import com.qf.give_a_like.domain.User;
import com.qf.give_a_like.response.Response;
import com.qf.give_a_like.service.CradService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/crad")
@RequiredArgsConstructor
public class CradController {


    private final CradService cradService;

    //查询全部
    @RequestMapping("showAll")
    public Response<PageInfo<Crad>> showall(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Crad> crads = cradService.showAll();
        PageInfo<Crad> pageInfo = new PageInfo<>(crads);
        return Response.success(pageInfo);
    }

    //新增名片
    @PostMapping("insert")
    public Response<Crad> insert(Crad crad){
        cradService.addCrad(crad);
        return Response.success();
    }

    //查看单个名片
    @GetMapping("browse")
    public Response<Crad> browse(Integer id){
        Crad crad = cradService.selectById(id);
        return Response.success(crad);
    }

    //喜欢的名片列表
    @GetMapping("likes")
    public Response<PageInfo<Crad>> like(String likeIds,Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Crad> crads = cradService.selectByIds(likeIds);
        PageInfo<Crad> PageInfo = new PageInfo<>(crads);
        return Response.success(PageInfo);
    }


    //自己的名片信息
    @GetMapping("/selectOneself")
    public Response<Crad> selectOneself(Integer id){
        Crad crad = cradService.selectOneself(id);
        return Response.success(crad);
    }
}
